package com.base.cn.platform.os.controller.marketing.shortLink;

import com.base.cn.platform.os.common.controller.BaseController;
import com.base.cn.platform.os.common.utils.result.ResultUtil;
import com.base.cn.platform.os.entity.marketing.shortLink.ShortLink;
import com.base.cn.platform.os.service.marketing.shortLink.ShortLinkBiz;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 短链接加密Controller
 *
 * @author zsw
 * @since 2019-04-22
 */
@RestController
@RequestMapping("/manage")
public class ShortLinkController extends BaseController {

    @Autowired
    private ShortLinkBiz shortLinkBiz;

    /**
     * 查询短链接
     *
     * @param shortLink
     * @return
     */
    @RequestMapping("/queryShortLink")
    public List<ShortLink> queryShortLink(@RequestBody ShortLink shortLink){

        /*if (StringUtils.isEmpty(shortLink.getUniqueValue())){
            return ResultUtil.ERROR("查询的短链接唯一值不能为空");
        }*/
        List<ShortLink> shortLinks = shortLinkBiz.queryShortLink(shortLink);
        return shortLinks;
//        return ResultUtil.SUCCESS("查询成功",_shortLink);
    }

    /**
     * 生成短链接
     *
     * @param longUrl 长链接
     * @return String 短链接
     */
    @RequestMapping("/createShortLink")
    public Map<String,Object> createShortLink(@RequestParam("longUrl") String longUrl) {
        if (StringUtils.isEmpty(longUrl)){
            return ResultUtil.ERROR("转换的链接不能为空");
        }
        String shortLink = shortLinkBiz.createShortLink(longUrl);
        return ResultUtil.SUCCESS("链接转换成功",shortLink);
    }

}
